﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MarketPlace.Web.Models;

namespace MarketPlace.Web.Controllers
{
    public partial class HomeController : BaseController
    {
        //
        // GET: /Home/

        [OutputCache(Duration = 60, VaryByParam = "None")]
        public virtual ActionResult Index()
        {
            //var qry = db.News.Count();

            return View();
        }

        /// <summary>
        /// 独家新闻
        /// </summary>
        /// <returns></returns>
        public ActionResult OnlyNews()
        {
            var qry = from x in db.OnlyNews
                      where x.IsPublished == true
                      orderby x.Id descending
                      select new NewsTitle
                      {
                          Id = x.Id,
                          Title = x.Title,
                          CreatedOn = x.CreatedOn
                      };

            ViewData["redcount"] = 3;

            var data = new NewsTitleList()
            {
                Items = qry.Take(10).ToList(),
                RedCount = 3,
                ShowDate = true
            };

            return PartialView("NewsList", data);
        }

        /// <summary>
        /// 新闻头条
        /// </summary>
        /// <returns></returns>
        public ActionResult NewsHeader()
        {
            var qry = from x in db.News
                      where x.IsPublished == true
                      orderby x.Id descending
                      select new NewsTitle
                      {
                          Id = x.Id,
                          Title = x.Title,
                          CreatedOn = x.CreatedOn
                      };

            ViewData["redcount"] = 3;

            var data = new NewsTitleList()
            {
                Items = qry.Take(9).ToList(),
                RedCount = 3,
                ShowDate = true
            };

            return PartialView("NewsList", data);
        }

        /// <summary>
        /// 市场咨询
        /// </summary>
        /// <returns></returns>
        public ActionResult MarketNews()
        {
            var qry = from x in db.MarketNews
                      where x.IsPublished == true
                      orderby x.Id descending
                      select new NewsTitle
                      {
                          Id = x.Id,
                          Title = x.Title,
                          ProductName = x.ProductName,
                          CreatedOn = x.CreatedOn
                      };

            ViewData["redcount"] = 3;

            var data = new NewsTitleList()
            {
                Items = qry.Take(9).ToList(),
                RedCount = 3
            };

            return PartialView(data);
        }

        /// <summary>
        /// 水产病例
        /// </summary>
        /// <returns></returns>
        public ActionResult MedicalRecords()
        {
            var qry = from x in db.MedicalRecords
                      where x.IsPublished == true
                      orderby x.Id descending
                      select new NewsTitle
                      {
                          Id = x.Id,
                          Title = x.Title,
                          CreatedOn = x.CreatedOn
                      };

            ViewData["redcount"] = 3;

            var data = new NewsTitleList()
            {
                Items = qry.Take(9).ToList(),
                RedCount = 3,
                ShowDate = false
            };

            return PartialView("NewsList", data);
        }

        /// <summary>
        /// 培训基地
        /// </summary>
        /// <returns></returns>
        public ActionResult TrainingInfos()
        {
            var qry = from x in db.TrainingInfos
                      where x.IsPublished == true
                      orderby x.Id descending
                      select new NewsTitle
                      {
                          Id = x.Id,
                          Title = x.Title,
                          CreatedOn = x.CreatedOn
                      };

            ViewData["redcount"] = 3;

            var data = new NewsTitleList()
            {
                Items = qry.Take(9).ToList(),
                RedCount = 3,
                ShowDate = false
            };

            return PartialView("NewsList", data);
        }    

        public ActionResult IndexTalentList()
        {
            return PartialView();
        }

        public virtual ActionResult Test()
        {
            return Content(db.News.Count().ToString() + "," + db.SiteDocs.Count().ToString());
        }
    }
}
